<template>
  <el-dialog
    title="选择优惠劵"
    :visible.sync="dialogVisible"
    width="898px"
    :before-close="handleClose"
    class="material"
  >
    <div style="color:#ababb2;position:absolute;left:75px;top:21px;">
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;（建议3-4张，请在优惠卷中添加优惠卷）
    </div>
    <div class="metarial-table">
      <el-table
        ref="multipleTable"
        :data="listData"
        header-cell-class-name="table-header-cell"
        row-class-name="table-row-one"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55" align="center">
        </el-table-column>
        <el-table-column
          label="优惠券名称"
          width="200"
          property="title"
        ></el-table-column>
        <el-table-column property="type" label="优惠券类型" align="center">
          <template slot-scope="scope">
            {{ scope.row.type == 0 ? "满减劵" : "折扣劵" }}
          </template>
        </el-table-column>
        <el-table-column property="time" label="有效时间" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.type_time === 1">
              {{ scope.row.stime }} 至 {{ scope.row.etime }}</span
            >
            <span v-else
              >领取{{ scope.row.stime }}天后生效，{{
                scope.row.etime === 0
                  ? "永久有效"
                  : `有效期${scope.row.etime}天`
              }}
            </span>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div style="width:100%;  text-align: center;">
      <el-pagination
        :page-size="10"
        layout="prev, pager, next"
        :total="totals"
        style="margin-top:10px;"
        @current-change="changes"
      >
      </el-pagination>
    </div>
    <div class="material-btn">
      <el-button size="small" class="btn1 btn" @click="handleClose"
        >取 消</el-button
      >
      <el-button size="small" type="primary" class="btn2 btn" @click="addImg"
        >确 定</el-button
      >
    </div>
  </el-dialog>
</template>

<script>
import { COUPON_LIST } from "@/service/shop";

export default {
  props: {
    alertCoupon: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      group_id: "",
      dialogVisible: this.alertCoupon,

      listData: [],
      multipleSelection: [],
      totals: 0,
      pages: 1
    };
  },
  watch: {
    alertCoupon(val) {
      this.dialogVisible = val;
      if (val) {
        this.init();
      }
    }
  },
  created() {},
  methods: {
    async init() {
      this.listData = [];

      await COUPON_LIST({
        page: this.pages,
        pageshow: 10,
        type: 1
      }).then(({ code, data, msg }) => {
        if (code === 200) {
          this.totals = data.count;
          this.listData = data.list;
        } else {
          this.$message.error(msg);
        }
      });
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    changes(page) {
      this.pagesList = page;
      this.init();
    },
    handleClose() {
      this.dialogVisible = false;
      this.$emit("close");
    },
    addImg() {
      this.$emit("couponChange", this.multipleSelection);
      this.dialogVisible = false;
      this.$emit("close");
    }
  }
};
</script>

<style scoped lang="scss">
.currentImg {
  border: 2px solid #00ffff !important;
}
.material .el-dialog__header {
  border-bottom-color: transparent !important;
}
.material-btn {
  height: 100px;
  position: relative;
  .btn {
    position: absolute;
    right: 16px;
    top: 40px;
  }
  .btn1 {
    right: 100px;
  }
}
.metarial-table {
  border: 1px solid #e9e9e9;
  transform: scale(0.98);
  transform-origin: left top;
  margin-left: 20px;
  margin-top: 30px;
}
</style>
